<?php

class ActionRegister2_Confirm extends BaseAction
{
    public function run()
    {
        $sVerifyCode = Yii::app()->request->getParam('code');

        $oVerifyCode = VerifyCode::model()->findByAttributes(array('code' => $sVerifyCode));

        $this->template->bIsFound = false;
        $this->template->bIsConfirmed = false;

        if ($oVerifyCode)
        {
            $this->template->bIsFound = true;

            if ((int)$oVerifyCode->is_confirmed !== 1)
            {
                $oUser = User::model()->findByPk($oVerifyCode->user_id);
                $oUser->status = 'active';
                $oUser->update();

                $oVerifyCode->is_confirmed = 1;
                $oVerifyCode->update();

                $this->template->bIsConfirmed = true;
            }
        }
    }
}